﻿package plugin.npcDialog.ui.panels.hctwo
{
    import cmd.*;
    import com.core.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import uiresource.npcdialogs.*;

    public class ShenzhuangHCPL extends SzhcUI implements INpcDialogContent
    {
        private var newshcgonfig:Object;
        private var itemconfig:Object;
        private var erjiArr:Array;
        private var dj_int:int;
        private var user_sex:int;
        private var userid:int;
        private var rein:int;
        private var _armrein:int;

        public function ShenzhuangHCPL()
        {
            this.newshcgonfig = ConfigDictionary.data.newsrl;
            this.itemconfig = ConfigDictionary.data.item;
            this.erjiArr = [];
            return;
        }// end function

        public function close() : void
        {
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            return;
        }// end function

        public function show(param1:Object, param2:Object) : void
        {
            var _loc_6:Object = null;
            var _loc_7:int = 0;
            var _loc_9:Object = null;
            hcLVbox.visible = true;
            erjibox.visible = false;
            shuomingLink.visible = false;
            fanhuiLink.visible = false;
            fanhuiLink.addEventListener(MouseEvent.CLICK, this.Onfanhui);
            shuomingLink.addEventListener(MouseEvent.MOUSE_OVER, this.OnSmtip);
            this.userid = UserData.getUserData("career");
            var _loc_3:* = UserData.getUserData();
            this.user_sex = _loc_3.sex;
            this.rein = _loc_3.rein;
            var _loc_4:Array = [];
            var _loc_5:Array = [];
            var _loc_8:Array = [];
            txt_desc.text = "神装合成可以将背包内没有强化的装备合成神装";
            txt_desc.align = "center";
            if (this.userid == 1)
            {
                name = "战士";
            }
            else if (this.userid == 2)
            {
                name = "法师";
            }
            else
            {
                name = "道士";
            }
            title_hec.text = name + "套装合成";
            for each (_loc_6 in this.newshcgonfig)
            {
                
                if (_loc_6.armrein)
                {
                    _loc_8.push(_loc_6.armrein);
                }
            }
            _loc_5 = this.filterArray(_loc_8);
            _loc_5.sort(Array.NUMERIC);
            _loc_7 = 0;
            while (_loc_7 < _loc_5.length)
            {
                
                for each (_loc_9 in this.newshcgonfig)
                {
                    
                    if (_loc_9.armrein == _loc_5[_loc_7])
                    {
                        _loc_4.push(_loc_9);
                        break;
                    }
                }
                _loc_7++;
            }
            LIsthec.array = _loc_4;
            LIsthec.renderHandler = new Handler(this.Listrend);
            return;
        }// end function

        protected function Onfanhui(event:MouseEvent) : void
        {
            hcLVbox.visible = true;
            erjibox.visible = false;
            shuomingLink.visible = false;
            fanhuiLink.visible = false;
            return;
        }// end function

        protected function OnSmtip(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "normal", "<font color = \'#997f60\'>只可以合成自己对应职业的神装</font>");
            shuomingLink.addEventListener(MouseEvent.MOUSE_OUT, this.OnSmclosetip);
            return;
        }// end function

        protected function OnSmclosetip(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            shuomingLink.removeEventListener(MouseEvent.MOUSE_OUT, this.OnSmclosetip);
            return;
        }// end function

        private function Listrend(param1:Component, param2:int) : void
        {
            var _loc_3:LinkButton = null;
            if (param2 < LIsthec.length)
            {
                _loc_3 = param1.getChildByName("lvLabel60") as LinkButton;
                _loc_3.label = "合成神·" + LIsthec.array[param2].armrein + "转装备";
                if (LIsthec.array[param2].id != LIsthec.array[param2].armrein)
                {
                    _loc_3.labelColors = "0x53b436,0xe19f21,0x53b436,0xe19f21";
                    _loc_3.addEventListener(MouseEvent.CLICK, this.OnClick60);
                }
                else
                {
                    _loc_3.labelColors = "0x73716B";
                }
            }
            return;
        }// end function

        protected function OnClick60(event:MouseEvent) : void
        {
            this.dj_int = ((event.currentTarget as LinkButton).parent as Component).dataSource.rein;
            this._armrein = ((event.currentTarget as LinkButton).parent as Component).dataSource.armrein;
            this.showlist(this.dj_int);
            return;
        }// end function

        private function showlist(param1:int) : void
        {
            var _loc_2:String = null;
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            if (this.userid == 1)
            {
                _loc_2 = "战士";
            }
            else if (this.userid == 2)
            {
                _loc_2 = "法师";
            }
            else
            {
                _loc_2 = "道士";
            }
            erjibox.visible = true;
            hcLVbox.visible = false;
            shuomingLink.visible = true;
            fanhuiLink.visible = true;
            this.erjiArr = [];
            titleLb.text = _loc_2 + "神·" + this._armrein + "转套装合成";
            for each (_loc_3 in this.newshcgonfig)
            {
                
                if (_loc_3.rein == param1)
                {
                    if (_loc_3.career == this.userid && _loc_3.sex == 2 || _loc_3.career == this.userid && _loc_3.sex == this.user_sex)
                    {
                        _loc_4 = {};
                        _loc_4.cfg = this.itemconfig[_loc_3.id];
                        _loc_4.armrein = _loc_3.armrein;
                        _loc_4.rein = _loc_3.rein;
                        _loc_4.cls = _loc_3.cls;
                        this.erjiArr.push([_loc_4.cfg, _loc_4.armrein, _loc_4.rein, _loc_4.cls, _loc_3.count, this.itemconfig[_loc_3.needitem]]);
                    }
                }
            }
            _list.array = this.erjiArr;
            _list.renderHandler = new Handler(this.ComlistRander);
            return;
        }// end function

        private function ComlistRander(param1:Component, param2:int) : void
        {
            var _loc_3:Label = null;
            var _loc_4:LinkButton = null;
            var _loc_5:LinkButton = null;
            var _loc_6:String = null;
            var _loc_7:LinkButton = null;
            var _loc_8:int = 0;
            if (param2 < _list.array.length)
            {
                _loc_3 = param1.getChildByName("denghao") as Label;
                _loc_4 = param1.getChildByName("xuyaoLabel") as LinkButton;
                _loc_5 = param1.getChildByName("lvname") as LinkButton;
                if (_list.array[param2][3] == 2)
                {
                    _loc_6 = "戒指";
                }
                if (_list.array[param2][3] == 3)
                {
                    _loc_6 = "手镯";
                }
                if (_list.array[param2][3] == 8)
                {
                    _loc_6 = "项链";
                }
                if (_list.array[param2][3] == 4)
                {
                    _loc_6 = "头盔";
                }
                if (_list.array[param2][3] == 6)
                {
                    _loc_6 = "鞋子";
                }
                if (_list.array[param2][3] == 7)
                {
                    _loc_6 = "腰带";
                }
                _loc_5.label = "神·" + _list.array[param2][1] + "转" + _loc_6;
                _loc_5.removeEventListener(MouseEvent.MOUSE_OVER, this.OnOverlvtips);
                _loc_5.addEventListener(MouseEvent.MOUSE_OVER, this.OnOverlvtips);
                _loc_4.label = _list.array[param2][1] + "转" + _loc_6 + " X" + _list.array[param2][4];
                _loc_4.removeEventListener(MouseEvent.MOUSE_OVER, this.OnOverxuyaotips);
                _loc_4.addEventListener(MouseEvent.MOUSE_OVER, this.OnOverxuyaotips);
                _loc_7 = param1.getChildByName("hcname") as LinkButton;
                _loc_7.addEventListener(MouseEvent.CLICK, this.OnClickbtn);
                _loc_8 = this.getallcount(_list.array[param2][1], _list.array[param2][3]);
                if (_loc_8 < _list.array[param2][4])
                {
                    _loc_7.labelColors = "0x73716B";
                    _loc_4.labelColors = "0x73716B";
                    _loc_5.labelColors = "0x73716B";
                    _loc_3.color = "0x73716B";
                }
                else
                {
                    _loc_7.labelColors = "0x53b436,0xe19f21,0x53b436,0xe19f21";
                    _loc_4.labelColors = "0x53b436,0xe19f21,0x53b436,0xe19f21";
                    _loc_5.labelColors = "0x53b436,0xe19f21,0x53b436,0xe19f21";
                    _loc_3.color = "0x53b436";
                }
            }
            return;
        }// end function

        protected function OnOverxuyaotips(event:MouseEvent) : void
        {
            var _loc_2:* = ((event.currentTarget as LinkButton).parent as Component).dataSource[5];
            ModelProxy.change("tips", "arm", {data:_loc_2, p:new Point(event.stageX, event.stageY)});
            event.currentTarget.addEventListener(MouseEvent.MOUSE_OUT, this.OnClosexuyaotips);
            return;
        }// end function

        protected function OnClosexuyaotips(event:MouseEvent) : void
        {
            event.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, this.OnCloselvtips);
            ModelProxy.change("tips", "state", "close");
            return;
        }// end function

        protected function OnOverlvtips(event:MouseEvent) : void
        {
            var _loc_2:* = ((event.currentTarget as LinkButton).parent as Component).dataSource[0];
            ModelProxy.change("tips", "arm", {data:_loc_2, p:new Point(event.stageX, event.stageY)});
            event.currentTarget.addEventListener(MouseEvent.MOUSE_OUT, this.OnCloselvtips);
            return;
        }// end function

        protected function OnCloselvtips(event:MouseEvent) : void
        {
            event.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, this.OnClosexuyaotips);
            ModelProxy.change("tips", "state", "close");
            return;
        }// end function

        protected function OnClickbtn(event:MouseEvent) : void
        {
            var _loc_2:* = ((event.currentTarget as LinkButton).parent as Component).dataSource[0].itemid;
            PluginManager.instance.sendToServer("qianghua", CMDQiangHua.DoCompound2, _loc_2);
            return;
        }// end function

        public function getallcount(param1:int, param2:int) : int
        {
            var _loc_7:Object = null;
            var _loc_8:Number = NaN;
            var _loc_3:int = 0;
            var _loc_4:* = UserData.getBagData();
            var _loc_5:* = UserData.getBagData().maxcount;
            var _loc_6:int = 1;
            while (_loc_6 < _loc_5)
            {
                
                _loc_7 = _loc_4[_loc_6];
                if (_loc_7)
                {
                    if (_loc_7[4] && _loc_7[4].reinlv == param1 && _loc_7[4].superlevel == 0 && _loc_7[4].cls == param2 && _loc_7[4].career == this.userid && _loc_7[4].suitid == 0)
                    {
                        if (_loc_7[3] > 0)
                        {
                            _loc_8 = ModelProxy.getValue("data", "servertime") + Number(getTimer());
                            if (_loc_7[3] < _loc_8)
                            {
                                ;
                            }
                        }
                        _loc_3 = _loc_3 + _loc_7[1];
                    }
                }
                _loc_6++;
            }
            return _loc_3;
        }// end function

        public function update(param1:Object, param2:int = 0) : void
        {
            this.showlist(this.dj_int);
            return;
        }// end function

        private function filterArray(param1:Array) : Array
        {
            var _loc_2:Array = [];
            var _loc_3:* = param1.length;
            var _loc_4:uint = 0;
            while (_loc_4 < _loc_3)
            {
                
                if (_loc_2.indexOf(param1[_loc_4]) == -1)
                {
                    _loc_2.push(param1[_loc_4]);
                }
                _loc_4 = _loc_4 + 1;
            }
            return _loc_2;
        }// end function

    }
}
